<?php
	class cPHPGrouper
	{
		const C_STR_AH_JS_LIB = "C:/xampp/htdocs/AmpleHarvest/JS";

		public static function _Data_Model_CMetaData($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output[] = "$str_BaseDir.\"/Data/Model/cMetadata.php\"";

			return $arr_Output;
		}

		public static function _EventHandler_CWindowEvents($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output[] = "$str_BaseDir.\"/EventHandler/cWindowEvents.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_CAreaCenter($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output = array_merge($arr_Output, self::_GUI_Article_CArticleView($str_BaseDir));
			$arr_Output = array_merge($arr_Output, self::_GUI_Article_CMetaData($str_BaseDir));
			$arr_Output[] = "$str_BaseDir.\"/GUI/article/cAreaCenter.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_CAreaEast($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output = array_merge($arr_Output, self::_GUI_Article_Enhancement_CCE_CCCE($str_BaseDir));
			$arr_Output = array_merge($arr_Output, self::_GUI_Article_Enhancement_Hierarchydata_CHierarchyData($str_BaseDir));
			$arr_Output = array_merge($arr_Output, self::_GUI_Article_Enhancement_MetaData_CMetaData($str_BaseDir));
			$arr_Output[] = "$str_BaseDir.\"/GUI/article/cAreaEast.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_CAreaWest($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output = array_merge($arr_Output, self::_GUI_Article_Navigation_CBreadcrumbs($str_BaseDir));
			$arr_Output = array_merge($arr_Output, self::_GUI_Article_Navigation_CFiles($str_BaseDir));
			$arr_Output = array_merge($arr_Output, self::_GUI_Article_Navigation_CHighlight($str_BaseDir));
			$arr_Output = array_merge($arr_Output, self::_GUI_Article_Navigation_CPages($str_BaseDir));
			$arr_Output[] = "$str_BaseDir.\"/GUI/article/cAreaWest.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_CArticle($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output = array_merge($arr_Output, self::_GUI_Article_CAreaCenter($str_BaseDir));
			$arr_Output = array_merge($arr_Output, self::_GUI_Article_CAreaEast($str_BaseDir));
			$arr_Output = array_merge($arr_Output, self::_GUI_Article_CAreaWest($str_BaseDir));
			$arr_Output[] = "$str_BaseDir.\"/GUI/article/cArticle.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_CArticleView($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output[] = "$str_BaseDir.\"/GUI/article/cArticleView.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_CMetaData($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output[] = "$str_BaseDir.\"/GUI/article/cMetaData.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_Enhancement_CCE_CCCE($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output[] = "$str_BaseDir.\"/GUI/article/enhancement/cce/cCCE.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_Enhancement_Hierarchydata_CHierarchyData($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output[] = "$str_BaseDir.\"/GUI/article/enhancement/hierarchydata/cHierarchyData.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_Enhancement_MetaData_CMetaData($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output = array_merge($arr_Output, self::_Data_Model_CMetaData($str_BaseDir));
			$arr_Output[] = "$str_BaseDir.\"/GUI/article/enhancement/metadata/cMetaData.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_Navigation_CBreadcrumbs($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output = array_merge($arr_Output, self::_EventHandler_CWindowEvents($str_BaseDir));
			$arr_Output[] = "$str_BaseDir.\"/GUI/article/navigation/breadcrumbs/cBreadcrumbs.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_Navigation_CFiles($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output = array_merge($arr_Output, self::_EventHandler_CWindowEvents($str_BaseDir));
			$arr_Output = array_merge($arr_Output, self::_GUI_Article_Navigation_Files_CContextmenu($str_BaseDir));
			$arr_Output = array_merge($arr_Output, self::_GUI_Article_Navigation_Files_CToolbar($str_BaseDir));
			$arr_Output = array_merge($arr_Output, self::_GUI_Article_Navigation_Files_CToolTip($str_BaseDir));
			$arr_Output[] = "$str_BaseDir.\"/GUI/article/navigation/files/cFiles.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_Navigation_CHighlight($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output = array_merge($arr_Output, self::_GUI_Article_Navigation_Highlight_CToolbar($str_BaseDir));
			$arr_Output[] = "$str_BaseDir.\"/GUI/article/navigation/highlight/cHighlight.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_Navigation_CPages($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output = array_merge($arr_Output, self::_EventHandler_CWindowEvents($str_BaseDir));
			$arr_Output[] = "$str_BaseDir.\"/GUI/article/navigation/pages/cPages.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_Navigation_Files_CContextmenu($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output[] = "$str_BaseDir.\"/GUI/article/navigation/files/cContextMenu.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_Navigation_Files_CToolbar($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output[] = "$str_BaseDir.\"/GUI/article/navigation/files/cToolbar.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_Navigation_Files_CToolTip($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output[] = "$str_BaseDir.\"/GUI/article/navigation/files/cToolTip.php\"";

			return $arr_Output;
		}

		public static function _GUI_Article_Navigation_Highlight_CToolbar($str_BaseDir)
		{
			$arr_Output = array();

			$arr_Output[] = "$str_BaseDir.\"/GUI/article/navigation/highlight/cToolbar.php\"";

			return $arr_Output;
		}

		public static function create_OutputFile($str_Dir, $str_Name)
		{
			if (!file_exists($str_Dir))
			{
				mkdir($str_Dir, 0777, true);
			}

			return fopen($str_Dir . "/" . $str_Name, 'w');

		}

		public static function get_DefaultIncludes()
		{
			$str_Output = "";

			$str_Output .= "<?php\n";

			$str_Output .= "require_once dirname(dirname(dirname(__FILE__))) . \"/config/cConfig.php\";\n";

			$str_Output .= "?>\n";

			return $str_Output;
		}

		public static function get_Index()
		{
			$arr_Output = array();
			$arr_Output[] = "dirname(dirname(dirname(__FILE__))).\"/EventHandler/cWindowEvents.php\"";
			$arr_Output[] = "dirname(dirname(dirname(__FILE__))).\"/EventHandler/cMenuEvents.php\"";
			$arr_Output[] = "dirname(dirname(dirname(__FILE__))).\"/layout/cMenu.php\"";
			$arr_Output[] = "dirname(dirname(dirname(__FILE__))).\"/layout/cClassBanner.php\"";
			$arr_Output[] = "dirname(dirname(dirname(__FILE__))).\"/layout/cHeader.php\"";
			$arr_Output[] = "dirname(dirname(dirname(__FILE__))).\"/layout/cLayout.php\"";
			$arr_Output[] = "dirname(dirname(dirname(__FILE__))).\"/layout/menu/cHelpMenu.php\"";

			$arr_Output = array_unique($arr_Output);

			//print_r($arr_Output);

			//die();

			return $arr_Output;
		}

		public static function get_ArticleIndex()
		{
			$str_BaseDir = "dirname(dirname(dirname(dirname(__FILE__))))";
			$arr_Output = array();

			$arr_Output = array_merge($arr_Output, self::_EventHandler_CWindowEvents($str_BaseDir));
			$arr_Output[] = "$str_BaseDir.\"/EventHandler/cMenuEvents.php\"";
			$arr_Output[] = "$str_BaseDir.\"/layout/cMenu.php\"";
			$arr_Output[] = "$str_BaseDir.\"/layout/cClassBanner.php\"";
			$arr_Output[] = "$str_BaseDir.\"/layout/cHeader.php\"";
			$arr_Output[] = "$str_BaseDir.\"/layout/cLayout.php\"";
			$arr_Output[] = "$str_BaseDir.\"/layout/menu/cHelpMenu.php\"";
			$arr_Output[] = "$str_BaseDir.\"/layout/cViewPort.php\"";

			$arr_Output = array_merge($arr_Output, self::_GUI_Article_CArticle($str_BaseDir));

			$arr_Output = array_unique($arr_Output);

			//print_r($arr_Output);

			//die();

			return $arr_Output;
		}
	}

	$str_BasePath = dirname(dirname(dirname(dirname(__FILE__)))) . "/webpages/JS/compressed/pages/";

	//Build EXTJS for page/index.php

	$arr_JSFiles = cPHPGrouper::get_Index();
	$str_OutputName = "index.php";

	print("Building PHP file for pages/index.php...\n");
	print("Outputing to $str_BasePath/$str_OutputName...\n");

	$obj_OutputFile = cPHPGrouper::create_OutputFile($str_BasePath, $str_OutputName);
	if (!$obj_OutputFile)
	{
		die("Failed to create Output File.");
	}

	fwrite($obj_OutputFile, "<?php\n");
	foreach ($arr_JSFiles as $str_File)
	{
		print("Adding - $str_File\n");
		fwrite($obj_OutputFile, "include($str_File);\n");
		//fwrite($obj_OutputFile, file_get_contents($str_File));
	}

	fwrite($obj_OutputFile, "?>\n");

	fclose($obj_OutputFile);

	//Build EXTJS for page/Article/index.php

	$arr_JSFiles = cPHPGrouper::get_ArticleIndex();
	$str_OutputDir = $str_BasePath . "article";
	$str_OutputName = "index.php";

	print("Building PHP file for pages/article/index.php...\n");
	print("Outputing to $str_OutputDir/$str_OutputName...\n");

	$obj_OutputFile = cPHPGrouper::create_OutputFile($str_OutputDir, $str_OutputName);
	if (!$obj_OutputFile)
	{
		die("Failed to create Output File.");
	}

	fwrite($obj_OutputFile, "<?php\n");
	foreach ($arr_JSFiles as $str_File)
	{
		print("Adding - $str_File\n");
		fwrite($obj_OutputFile, "include($str_File);\n");
		//fwrite($obj_OutputFile, file_get_contents($str_File));
	}

	fwrite($obj_OutputFile, "?>\n");

	fclose($obj_OutputFile);
